<?php
namespace app\admin\controller;
use think\Loader;
class Account extends Base
{

    //账号列表
    public function index(){
        $invoking     = Loader::model('Account','service');
        $data         = $invoking->adminList();
        $this->assign('list', $data['list']);
        return $this->fetch();
    }

    //添加账号
    public function add(){
        $admin_id     = input('admin_id');
        $invoking     = Loader::model('Account','service');
        $list         = $invoking->roleListAdd();
        $data         = '';
        if(empty($admin_id)){
            $title = '新增账号';
        }else{
            $title = '编辑账号';
            $data  = $invoking->adminFind($admin_id);
        }
        $this->assign('title', $title);
        $this->assign('list', $list);
        $this->assign('data', $data);
        return $this->fetch();
    }


    // 操作日志 单独账户
    public function managerlog(){
        $where['a.admin_id']=input('admin_id');
        $invoking     = Loader::model('Account','service');
        $data         = $invoking->managerlogList($where);
        $this->assign('list', $data['list']);
        $this->assign('user_name', $data['user_name']);
        $this->assign('page', $data['page']);
        return $this->fetch();
    }

    // 操作日志
    public function managerlogs(){
        $invoking     = Loader::model('Account','service');
        $data         = $invoking->managerlogList();
        $this->assign('list', $data['list']);
        $this->assign('page', $data['page']);
        return $this->fetch();
    }




    // 权限设置
    public function permission(){
        $invoking     = Loader::model('Account','service');
        $a_role=trim(input('a_role'));
        $data=$invoking->jurisdictionList($a_role);
        $this->assign('a_role',$a_role);
        $this->assign('default',$data['result']);
        $this->assign('list',$data['model_2']);
        $this->assign('r_username',$data['r_username']);
        return $this->fetch();
    }

    // 修改密码
    public function changepassword(){
        $admin_id=trim(input('admin_id'));
        $invoking     = Loader::model('Account','service');
        $data         = $invoking->AdminDemand($admin_id);
        $this->assign('data',$data);
        return $this->fetch();
    }



    //菜单列表
    public function menus(){
        $invoking     = Loader::model('Account','service');
        $where['am_pid']    = 0;
        $data         = $invoking->menusList($where);
        $this->assign('list', $data);
        return $this->fetch();
    }

    //菜单新增与编辑
    public function menusAdd(){
        $admin_menu_id = input('admin_menu_id');
        if(empty($admin_menu_id)){
            $title = '新增';
        }else{
            $invoking     = Loader::model('Account','service');
            $where['admin_menu_id']=$admin_menu_id;
            $data         = $invoking->menusInfo($where);
            $this->assign('info',$data);
            $title = '编辑';
        }
        $this->assign('title',$title);
        return $this->fetch();
    }

    //菜单子菜单列表
    public function sonmenus(){
        $invoking       = Loader::model('Account','service');
        $am_pid         = trim(input('am_pid'));
        $where['am_pid']= trim(input('am_pid'));
        $data           = $invoking->menusList($where);
        $this->assign('list',$data);
        $this->assign('am_pid',$am_pid);
        return $this->fetch();
    }

    //菜单子菜单添加
    public function sonmenusAdd(){
        $am_pid         = trim(input('am_pid'));
        $admin_menu_id  = trim(input('admin_menu_id'));
        if(!empty($admin_menu_id)){
            $invoking = Loader::model('Account','service');
            $where['admin_menu_id'] = $admin_menu_id;
            $data = $invoking->menusInfo($where);
            $title       = "编辑";
            $am_pid=$data['am_pid'];
            $this->assign('info',$data);
        }else{
            $title       = "新增";
        }
        $this->assign('title',$title);
        $this->assign('am_pid',$am_pid);
        return $this->fetch();
    }


    //功能列表
    public function feature(){
        $invoking = Loader::model('Account','service');
        $data     = $invoking->featureData();
        $this->assign('list',$data['list']);
        $this->assign('page',$data['page']);
        return $this->fetch();
    }

    //功能下级
    public function junior(){
        $invoking = Loader::model('Account','service');
        $data     = $invoking->juniorData();
        $this->assign('am_pid',input('admin_menu_id'));
        $this->assign('list',$data['list']);
        $this->assign('page',$data['page']);
        return $this->fetch();
    }


    //三级功能添加
    public function functionAdd(){
        $input              = input();
        $admin_function_id  = trim(input('admin_function_id'));
        $admin_menu_id      = trim(input('admin_menu_id'));
        $am_pid             = trim($input['am_pid']);
        if(!empty($admin_function_id)){
            $invoking = Loader::model('Account','service');
            $where['admin_function_id']=$admin_function_id;
            $info     = $invoking->fuInfoData($where);
            $title="编辑";
        }else{
            $info = null;
            $title="新增";
        }
        $this->assign('info',$info);
        $this->assign('title',$title);
        $this->assign('admin_function_id',$admin_function_id);
        $this->assign('admin_menu_id',$admin_menu_id);
        $this->assign('am_pid',$am_pid);
        return $this->fetch();
    }


    //三级功能详情
    public function fudetails(){
        $admin_menu_id  = trim(input('admin_menu_id'));
        $am_pid   = trim(input('am_pid'));
        $invoking = Loader::model('Account','service');
        $where['af_menuid']  = $admin_menu_id;
        $list=$invoking->fudetailsData($where);
        $this->assign('list',$list);
        $this->assign('admin_menu_id',$admin_menu_id);
        $this->assign('am_pid',$am_pid);
        return $this->fetch();
    }


    //角色管理
    public function role_list(){
        $invoking     = Loader::model('Account','service');
        $data         = $invoking->roleList();
        $this->assign('list', $data['list']);
        $this->assign('page', $data['page']);
        return $this->fetch();
    }

    //角色新增
    public function  role_add(){
        $role_id      = trim(input('role_id'));
        if(!empty($role_id)){
            $invoking     = Loader::model('Account','service');
            $data         = $invoking->roleData($role_id);
            $this->assign('data', $data);
        }
        return $this->fetch();
    }



}

